<%@taglib prefix="s" uri="/struts-tags"	%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<s:set var="name"><sec:authentication property="principal.username" /></s:set>

<s:action name="get" namespace="/users">
	<s:param name="username"><sec:authentication property="principal.username" /></s:param>
</s:action>

<article>	
	<h1><s:text name="profile.title"/>: <sec:authentication property="principal.username" /></h1>
	
	<s:if test="hasActionMessages()">
		<s:actionmessage />
	</s:if>
	<s:if test="hasActionErrors()">
		<s:actionerror />
	</s:if>
	
	<br/>
	<h3><s:text name="profile.usDet"/></h3>
	<s:form action="merge" namespace="/usrdetails" method="post">
		<s:textfield name="usrDetailsIns.name" key="details.name" value="%{#request.user.usrDetails.name}"/>
		<s:textfield name="usrDetailsIns.surname" key="details.surname" value="%{#request.user.usrDetails.surname}"/>
		<s:textfield name="usrDetailsIns.email" key="details.email" value="%{#request.user.usrDetails.email}"/>
		<s:textfield name="usrDetailsIns.birthdate" key="details.birthdate" value="%{#request.user.usrDetails.birthdate}" placeholder="%{getText('general.date.placeholder')}"/>
		<s:textfield name="usrDetailsIns.city" key="details.city" value="%{#request.user.usrDetails.city}"/>
		<s:textfield name="usrDetailsIns.address" key="details.address" value="%{#request.user.usrDetails.address}"/>
		<s:textfield name="usrDetailsIns.phoneNumber" key="details.phoneNumber" value="%{#request.user.usrDetails.phoneNumber}"/>
		<s:textfield name="usrDetailsIns.cellNumber" key="details.cellNumber" value="%{#request.user.usrDetails.cellNumber}"/>
		<s:textfield name="usrDetailsIns.taxCode" key="details.taxCode" value="%{#request.user.usrDetails.taxCode}"/>
		<s:hidden name="page" value="%{page}" />
		<s:hidden name="username" value="%{name}"/>
		<s:submit method="merge" key="general.edit" onclick="return confirm('Confirm?')" />
	</s:form>
	
	<s:url action="delete" namespace="/usrdetails" var="delUsrDet">
		<s:param name="usrDetails_id" value="%{#request.user.usrDetails.usrDetails_id}"/>
		<s:param name="username" value="%{#request.user.username}"/>
		<s:param name="page" value="%{page}"/>
	</s:url>
	<s:if test="%{#request.user.usrDetails!=null}">
		<span class="padleft"><s:a href="%{delUsrDet}" onclick="return confirm('Confirm?')"><s:text name="details.delete"/></s:a><br /></span>
	</s:if>
	
	<br/>
	<h3><s:text name="general.changePwd"/></h3>
	<s:form action="changePwd" namespace="/users" method="post">
		<s:password name="currentPassword" key="general.currentPassword"/>
		<s:password name="newPassword" key="general.newPassword"/>
		<s:password name="confirmPassword" key="general.confirmNewPassword"/>
		<s:hidden name="username" value="%{name}"/>
		<s:hidden name="page" value="%{page}"/>
		<s:submit method="changePwd" key="general.submit"/>
	</s:form>
	
	<br/>
	<div class="alignCenter">
		<sec:authorize access="hasRole('ROLE_ADMIN')">
			<p><a href="/Struts2_Template/redirect.action?page=admin/usersManagement"><s:text name="usMan.title"/></a></p>
			<p><a href="/Struts2_Template/redirect.action?page=admin/rolesGroupsManagement"><s:text name="roGrMan.title"/></a></p>
		</sec:authorize>
	</div>
</article>